-- ======================================================================
-- Hell Lua Bus
-- 
-- Copyright 2012-2013Hell-Prototypes
--
-- http://www.hellprototypes.com/
--
-- This is free software, licensed under the terms of the GNU General
-- Public License as published by the Free Software Foundation.
-- ======================================================================
hlb = require('libhlb')

function device_open()
	local ret = hlb.usb_open()
	if ret < 0 then
		print("Fail to open usb device")
		return false
	end
	
	return true
end

function device_close()
	local ret = hlb.usb_close()
	if ret < 0 then
		print("Fail to close usb device")
		return false
	end
	
	return true
end
-- -----------------------------------------------

device_open()

rs232 = {9600, 0}
ret = hlb.rs232_open(rs232)
print("hlb_rs232_open ret = " .. ret)

wr = {0x55, 1, 2, 3, 0xaa}
ret = hlb.rs232_wr(wr)
print("hlb_rs232_wr ret = " .. ret)

read = {}
read = hlb.rs232_rd(100, 0)
print("read len = " .. #read)
if #read > 0 then
	for i=1, #read do
		print(read[i])
	end
end


io.write("\r\nAny key to close device ...")
io.flush()
io.read()
print("")
ret = hlb.rs232_close()

device_close()
